<template>
  <view>
    <l-background has-sub-background />
    <view class="padding-30">
      <view class="card">
        <driver-info-model :data="driverInfo" :driver-info="driverInfo" default-img="https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb_admin_app/static/default_avatar.png" disabled />
      </view>

      <view class="card margin-top-14">
        <image-model :data="driverInfo" disabled :list="idCardList" />
      </view>

      <view class="card margin-top-14">
        <id-card-info-model :data="driverInfo" disabled />
        <contact-information-model :data="driverInfo" disabled />
      </view>

      <view class="card margin-top-14">
        <image-model :data="driverInfo" disabled :list="driverLicenseList" />
      </view>

      <view class="card margin-top-14">
        <identity-info-model :data="driverInfo" disabled />
      </view>
    </view>
  </view>
</template>

<script>
import DriverInfoModel from '../components/driver-info-model/driver-info-model'
import ContactInformationModel from '../components/contact-information-model/contact-information-model'
import IdCardInfoModel from '../components/id-card-info-model/id-card-info-model'
import IdentityInfoModel from '../components/identity-info-model/identity-info-model'
import { getDriverInfo } from '../api'
export default {
  name: 'DriverDetail',
  components: {
    DriverInfoModel,
    ContactInformationModel,
    IdCardInfoModel,
    IdentityInfoModel
  },
  data() {
    return {
      driverId: '',
      driverInfo: {
        idCard1: '',
        idCard2: '',
        licence1: '',
        certification: '',
		thirdYearNotMajorAccidentCert:''
      },
      showDataList: ['idCardNo', 'idCardValidDateEnd', 'address', 'emergentName', 'emergentPhone', 'entryDate', 'licenceNo', 'licenceType', 'issueDate', 'validEndDate', 'certificationValidDateEnd'],
      idCardList: [
        { attr: 'idCard1', label: '身份证正面', default: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb-portal/static/idcard.png' },
        { attr: 'idCard2', label: '身份证反面', default: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb-portal/static/idcardback.png' }
      ],
      driverLicenseList: [
        { attr: 'licence1', label: '驾驶证正本', default: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb-portal/static/singshizheng.png', example: true },
        { attr: 'certification', label: '从业资格证', default: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb-portal/static/zigezheng.png', example: true },
		{ attr: 'thirdYearNotMajorAccidentCert', label: '三年无重大事故证明', default: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb-portal/static/zigezheng.png', example: true }
	  ]
    }
  },
  onLoad(options) {
    if (options.id) {
      this.driverId = options.id
      this.getInfo()
    }
  },
  methods: {
    // 获取司机详情
    async getInfo() {
      const [err, res] = await getDriverInfo(this.driverId)
      if (!this.$http.errorCheck(err, res)) return false
      const data = res.data.data
      if (data.entryDate) data.entryDate = this.showDate(data.entryDate)
      if (data.issueDate) data.issueDate = this.showDate(data.issueDate)
      if (data.validEndDate) data.validEndDate = this.showDate(data.validEndDate)
      if (data.certificationValidDateEnd) data.certificationValidDateEnd = this.showDate(data.certificationValidDateEnd)
      if (data.validStartDate && !data.validEndDate) data.validEndDate = '长期'
      if (data.idCardValidDate && !data.idCardValidDateEnd) data.idCardValidDateEnd = '长期'
      this.showDataList.forEach(attr => {
        if (!data[attr]) data[attr] = '暂无'
      })
      this.driverInfo = data
      console.log(data)
    },
    // 展示时间
    showDate(date) {
      return date.substring(0, date.indexOf(' '))
    }
  }
}
</script>

<style scoped lang="scss">
@include setMargin(top,14);
</style>
